package com.me.libgdx_test;

import com.badlogic.gdx.graphics.g2d.Sprite;

public class ClassSpriteObjectPool {
	private ClassSpriteObject[] sprite_pool;
	private ClassLogDisplay logger;
	private int list_start;
	ClassSpriteObjectPool(Point board_size){
		sprite_pool = new ClassSpriteObject[board_size.x*board_size.y*3];
		logger = new ClassLogDisplay("ClassSpriteObjectPool");
		for(int i=0;i<sprite_pool.length;i++){
			sprite_pool[i] = new ClassSpriteObject(new Sprite());
		}
		list_start = 0;
	}
	public void free_list(){
		for(int i =0;i<sprite_pool.length;i++){
			sprite_pool[i].set_using(false);
		}
		list_start = 0;
	}
	public int find_next_open(){
		for(int i =0;i<sprite_pool.length;i++){
			if(sprite_pool[i].get_using()){
				return i;
			}
		}
		return -1;
	}

	public void add_sprite(Sprite sprite, Point location, Point size, boolean animation){
		if(list_start < sprite_pool.length){
			sprite_pool[list_start].get_sprite().set(sprite);
			sprite_pool[list_start].get_sprite().setPosition(location.x, location.y);
			sprite_pool[list_start].get_sprite().setSize(size.x, size.y);
			sprite_pool[list_start].set_using(true);
			sprite_pool[list_start].set_animation(animation);
			list_start++;
		}else{
			logger.print("Sprites exceeded list size. Need to reconfigure");
		}
	}
	public void print_pool(){
		logger.print("Printing Sprites");
		for(ClassSpriteObject sprite:sprite_pool){
			if(sprite.get_using()){
				logger.print(sprite.get_sprite().toString());
			}
		}
	}
	public ClassSpriteObject[] get_pool(){
		return sprite_pool;
	}
}
